//
//  CoursePlan.m
//  KeepProject
//
//  Created by amos on 16/1/20.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "CoursePlan.h"

@implementation CoursePlan

//1.从 plist 文件中加载模型数据
+ (NSArray*)plansFromPlist:(NSString*)fileName
{
    //1.获取路径
    NSString* path = [[NSBundle mainBundle] pathForResource:fileName ofType:nil];

    //2.获取数据
    NSArray* dictArr = [NSArray arrayWithContentsOfFile:path];

    //3.用于存储模型的临时可变数组
    NSMutableArray* modelArr = [NSMutableArray arrayWithCapacity:dictArr.count];

    //4.遍历数组取出
    for (NSDictionary* dict in dictArr) {
        CoursePlan* plan = [CoursePlan planWithDict:dict];

        [modelArr addObject:plan];
    }
    return modelArr.copy;
}

//2.通过字典初始化对象
+ (instancetype)planWithDict:(NSDictionary*)dict
{
    CoursePlan* plan = [[self alloc] init];

    [plan setValuesForKeysWithDictionary:dict];
    return plan;
}

- (void)setForce:(NSNumber*)stars
{
    _force = stars;

    NSString* type = nil;

    switch (stars.intValue) {
    case 1:
        type = @"零基础";
        break;
    case 2:
        type = @"入门";
        break;
    case 3:
        type = @"零基础";
        break;
    case 4:
        type = @"零基础";
        break;
    default:
        type = @"零基础";
        break;
    }

    _forceName = [NSString stringWithFormat:@"K%d %@", stars.intValue, type];
}

@end
